/*
*太原学院计算机科学与技术系（C）版权所有
* @author liyanrong
* @version 1.0
 */

package cn.edu.tyu.util;

import java.sql.*;

/**
 * MySQL数据库实用类
 *  @author liyanrong
 *  @version 1.0
 */
public class DbUtil {
    public static void main(String[] args){
        DbUtil dbUtil = new DbUtil();
        Connection conn = DbUtil.getConnection();
        System.out.println(conn);
    }
    public static Connection getConnection(){
        Connection conn = null;
        String url= "jdbc:mysql://localhost:3306/financedb";
        try{
            Class.forName("com.myaql.jdbc.Driver");
            conn = DriverManager.getConnection(url, "root","root");
        } catch (ClassNotFoundException e){
            e.printStackTrace();
        } catch (SQLException e){
            e.printStackTrace();
        }
        return conn;
    }
    public static void backConn(Connection conn, PreparedStatement ps, ResultSet rs){
        if(rs != null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(ps!=null) {
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
